"""
权限控制抽离, 预设角色权限规则

class DemoControl:

    class get:

"""
import logging
from collections import ChainMap, defaultdict
from enum import Enum
from typing import Union

from app.models.roleModel import PresetRoleChoices

logger = logging.getLogger(__name__)
SUPPORT_METHOD = ["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS", "HEAD"]


class ControlType(Enum):
    rule = "rule"
    blueprint = "blueprint"


class MateControl(type):

    PUBLIC_ATTRS = ("title", "description")
    CONTROL_ATTRS = ("limit_roles", "black_roles")
    DEFAULT_MENU_ATTRS = {
        "is_menu": False,
        "menu_name": "",
        "menu_url": "",
        "menu_order": 1000,
    }
    METHOD_ATTRS = SUPPORT_METHOD

    @classmethod
    def validate_attr(mcs, class_name, attrs: dict, method=None):

        if method is not None:
            method_cls = attrs[method]
            for val in mcs.PUBLIC_ATTRS:
                setattr(method_cls, val, getattr(method_cls, val, ""))
            for val in mcs.CONTROL_ATTRS:
                setattr(method_cls, val, getattr(method_cls, val, set()))
            _attrs = attrs[method].__dict__
        else:
            _attrs = attrs

        # 校验限制参数类型
        for item in mcs.CONTROL_ATTRS:
            if _attrs.get(item, None) and not isinstance(_attrs[item], set):
                raise AttributeError(
                    f"{class_name}{'.' + method if method is not None else ''} 中，属性 {item} 必须是集合"
                )

        # 校验自身限制参数
        null_set = set()
        if _attrs.get("limit_roles", null_set) & _attrs.get("black_roles", null_set):
            raise AttributeError(
                f"{class_name}{'.' + method if method is not None else ''} 中，limit_roles 和 black_roles不允许存在交集"
            )

        if method is not None:
            # 对角色限制进行校验
            if any(
                [
                    attrs.get("limit_roles", null_set)
                    & _attrs.get("black_roles", null_set),
                    attrs.get("black_roles", null_set)
                    & _attrs.get("limit_roles", null_set),
                ]
            ):
                raise AttributeError(
                    f"{class_name}.{method} 中`black_roles`或`limit_roles`与 {class_name} 配置冲突"
                )
            # 不允许rule的请求方法出现菜单控制
            elif any([_attrs.get(val, None) for val in mcs.DEFAULT_MENU_ATTRS]):
                raise AttributeError(
                    f"{class_name}.{method} 中不允许存在菜单控制，建议配置蓝图及其控制器，否则容易造成路由管理混乱"
                )

    @classmethod
    def validate(mcs, class_name, attrs, control_type=None):
        if control_type is None:
            raise AttributeError(f"Control类: {class_name} 缺少 control_type 属性")
        elif not isinstance(control_type, ControlType):
            raise AttributeError(
                f"Control类: {class_name} control_type 属性不属于ControlType"
            )

        has_method_attr = False
        for item in mcs.METHOD_ATTRS:
            if attrs.get(item):
                has_method_attr = True
                if control_type == ControlType.rule:
                    logger.info(f"{class_name} 中类属性 {mcs.CONTROL_ATTRS} 将被忽略")
                    mcs.validate_attr(class_name, attrs, method=item)
                elif control_type == ControlType.blueprint:
                    raise AttributeError(f"{class_name} 为蓝图控制器，不允许包含HTTP请求方法控制")

        if not has_method_attr:
            mcs.validate_attr(class_name, attrs)

        return has_method_attr

    def __new__(mcs, name, bases, attrs):

        if name == "BaseControl":
            base_handler = super().__new__(mcs, name, bases, attrs)
            return base_handler

        __control_type = None
        if len(bases) > 0:
            __control_type = bases[0].control_type

        control_type = attrs.get("control_type", __control_type)
        has_method_attr = mcs.validate(name, attrs, control_type=control_type)

        cls = super().__new__(mcs, name, bases, attrs)

        if control_type == ControlType.rule:
            setattr(cls, "has_method_attr", has_method_attr)

        return cls


class BaseBlueControl(metaclass=MateControl):
    """
    请求方法角色限制 与 类角色限制 将取交集
    """

    # rbac应用场景
    control_type = ControlType.blueprint

    # 蓝图/规则 标题和描述
    title = ""
    description = ""

    # 是否为菜单
    is_menu = False
    # 菜单名称
    menu_name = title
    # 前端菜单路由（支持角色枚举-前端路由的key-value模式）
    menu_url = ""
    # 权重排序
    menu_order = 1000

    # 优先处理limit_roles 忽略 black_roles
    # 限制访问的角色
    limit_roles = set()
    # 禁止访问的角色
    black_roles = set()

    # 锁定allow_roles内角色限制，不允许编辑
    lock = False
    # 是否在渲染权限树时展示
    show_node = True

    def __init__(self):
        self.method_limit = []

    @property
    def allow_roles(self):
        """获取允许访问当前控制节点的角色列表"""
        if self.limit_roles:
            return self.limit_roles

        return set(PresetRoleChoices) - self.black_roles

    def validate(self, request):

        allow = False
        user_roles: list = request.user.roles

        limit_roles = getattr(self, "limit_roles", [])
        black_roles = getattr(self, "black_roles", [])

        if not limit_roles and not black_roles:
            allow = True
        elif limit_roles and any([val for val in user_roles if val in limit_roles]):
            allow = True
        elif black_roles and any([val for val in user_roles if val not in black_roles]):
            allow = True

        return allow


class BaseRuleControl(metaclass=MateControl):
    """
    请求方法角色限制 与 类角色限制 将取交集
    """

    # rbac应用场景
    control_type = ControlType.rule

    # 蓝图/规则 标题和描述
    title = ""
    description = ""

    # 是否为菜单
    is_menu = False
    # 菜单名称
    menu_name = title
    menu_url = ""
    # 权重排序
    menu_order = 1000

    # 限制访问的角色
    limit_roles = set()
    # 禁止访问的角色
    black_roles = set()

    # 锁定allow_roles内角色限制，不允许编辑
    lock = False
    # 是否在渲染权限树时展示
    show_node = True

    @property
    def allow_roles(self) -> Union[dict, set]:
        """获取允许访问当前控制节点的角色列表"""
        if any(map(lambda x: getattr(self, x, None), SUPPORT_METHOD)):
            return self.method_allow_roles
        elif self.limit_roles:
            return self.limit_roles
        else:
            return set(PresetRoleChoices) - self.black_roles

    @property
    def method_allow_roles(self):
        """获取不同方法的角色限制"""
        result = defaultdict(set)
        for method in SUPPORT_METHOD:
            method_control = getattr(self, method, None)
            if method_control:
                _allow = (
                    method_control.limit_roles
                    if getattr(method_control, "limit_roles", None)
                    else set(PresetRoleChoices)
                    - getattr(method_control, "black_roles", set())
                )
                result[method] ^= _allow
        return result

    def validate(self, request):
        method_control = getattr(self, request.mothed, None)

        m_limit = []
        m_black = []
        if method_control:
            m_limit = getattr(method_control, "limit_roles", m_limit)
            m_black = getattr(method_control, "black_roles", m_black)
        limit_roles = ChainMap(getattr(self, "limit_roles", []), m_limit)
        black_roles = ChainMap(getattr(self, "black_roles", []), m_black)

        allow = False
        user_roles: set = request.user.roles

        if not limit_roles and not black_roles:
            allow = True
        elif limit_roles and any([val for val in user_roles if val in limit_roles]):
            allow = True
        elif black_roles and any([val for val in user_roles if val not in black_roles]):
            allow = True

        return allow


class DefaultRuleControl(BaseRuleControl):
    """所有未指定角色权限控制器的路由将使用该控制器
    传递 `role_control=False`, 设置None将视为False 将取消该行为
    """

    control_type = ControlType.rule

    title = ""
    description = ""


class DefaultBlueprintControl(BaseBlueControl):
    """所有未指定角色权限控制器的蓝图将使用该控制器"""

    control_type = ControlType.blueprint

    title = ""
    description = ""


class AuthServerControl(BaseBlueControl):

    title = "认证服务"
    description = ""

    show_node = False
    lock = True


class VerificationCodeControl(BaseBlueControl):

    title = "验证码服务"
    description = ""

    show_node = False
    lock = True


class CollectorControl(BaseBlueControl):

    limit_roles = {PresetRoleChoices.admin}
    lock = True
    show_node = False


class ParticipantBlueprintControl(BaseBlueControl):

    title = "竞技比赛"
    description = "竞技比赛模块"

    limit_roles = {PresetRoleChoices.student}

    is_menu = True
    menu_name = title


class MyAthleticsCompetitionControl(BaseBlueControl):

    title = "我的竞技比赛"
    description = "我的竞技比赛模块"

    is_menu = True
    menu_name = title
    menu_url = "/ctfMyMatchList"


class MyCTFmathRuleControl(BaseRuleControl):
    title = "我的ctf比赛详情"
    description = "我的ctf比赛详情接口"


class MyCTFmathListRuleControl(BaseRuleControl):
    title = "我的ctf比赛列表"
    description = "我的ctf比赛列表接口"


class MyCTFmathFlagRuleControl(BaseRuleControl):
    title = "我的ctf比赛答题"
    description = "我的ctf比赛答题接口"

    class POST:
        title = "答题"
        description = "答题"


class MyCTFLevelRuleControl(BaseRuleControl):
    title = "我的ctf关卡答题"
    description = "我的ctf关卡答题接口"

    class POST:
        title = "答题"
        description = "答题"


class StartEnvRuleControl(BaseRuleControl):
    title = "启动靶场环境"
    description = "启动靶场环境接口"

    class POST:
        title = "启动"
        description = "启动靶场环境"


class StartEnvVmRuleControl(BaseRuleControl):
    title = "开启比赛环境(启动虚拟机)"
    description = "开启比赛环境(启动虚拟机)接口"

    class POST:
        title = "开启"
        description = "开启环境"


class GetEnvVmStautsRuleControl(BaseRuleControl):
    title = "获取靶场活动状态"
    description = "获取靶场活动状态接口"

    class POST:
        title = "查询"
        description = "查询状态"


class MyRangeVmInfosRuleControl(BaseRuleControl):
    title = "获取靶场虚拟机列表"
    description = "获取靶场活动状态接口"

    class POST:
        title = "查询"
        description = "查询"


class MyActiveRangeRuleControl(BaseRuleControl):
    title = "销毁活动靶场及虚拟机"
    description = "销毁活动靶场及虚拟机接口"

    class DELETE:
        title = "销毁"
        description = "销毁活动靶场及虚拟机"


class MyRangeListRuleControl(BaseRuleControl):
    title = "我的靶场列表"
    description = "我的靶场列表接口"


class MyCombatMatchCompetitionControl(BaseBlueControl):

    title = "我的红蓝对抗"
    description = "我的红蓝对抗模块"

    is_menu = True
    menu_name = title
    menu_url = "/combatMyMatchList"


class MyCTFRedBlueFlagRuleControl(BaseRuleControl):
    title = "红蓝对抗flag提交"
    description = "红蓝对抗flag提交接口"

    class POST:
        title = "提交"
        description = "提交"


class MyCTFManualRuleControl(BaseRuleControl):
    title = "人工裁决"
    description = "我的人工裁决管理"


class MyCtfRedBlueScoreRuleControl(BaseRuleControl):
    title = "查看所在团队及成员成绩"
    description = "查看所在团队及成员成绩接口"


class MyCTFRedBlueListRuleControl(BaseRuleControl):
    title = "我的ctf红蓝比赛列表"
    description = "我的ctf红蓝比赛列表接口"

class MyCTFNoticeControl(BaseRuleControl):
    title = "我的ctf公告列表"
    description = "我的ctf公告列表"

class MyCTFRedBlueRuleControl(BaseRuleControl):
    title = "红蓝比赛详情"
    description = "红蓝比赛详情接口"


class MyRedBlueRangeInfoRuleControl(BaseRuleControl):
    title = "获取比赛下所有虚机"
    description = "获取比赛下所有虚机接口"


class MyCourseWareListRuleControl(BaseRuleControl):
    title = "课件列表"
    description = "课件列表接口"


class SubjectManagementControl(BaseBlueControl):

    title = "课题管理"
    description = "课题管理模块"

    limit_roles = {PresetRoleChoices.student}

    is_menu = True
    menu_name = title


class MySubjectControl(BaseBlueControl):

    title = "我的课题"
    description = "我的课题模块"

    is_menu = True
    menu_name = title
    menu_url = "/curriculumList"


class SystemSubjectControl(BaseBlueControl):

    title = "系统课题"
    description = "系统课题模块"

    is_menu = True
    menu_name = title
    menu_url = "/mySystemCourse"


class MyCommonControl(BaseBlueControl):

    title = "学生模块公共方法"
    description = "控制学生端各个模块使用的公共接口权限"

    limit_roles = {PresetRoleChoices.student}


class AdminBluPrintControl(BaseBlueControl):

    title = "系统管理后台"
    description = "系统管理后台相关模块"

    limit_roles = {PresetRoleChoices.admin}

    is_menu = True
    lock = True


class SystemManageControl(BaseBlueControl):

    title = "系统管理"
    description = "系统管理模块"

    is_menu = True
    lock = True


class ImageManageControl(BaseBlueControl):

    title = "镜像管理"
    description = "镜像管理模块"

    is_menu = True
    lock = True


class MonitorManageControl(BaseBlueControl):

    title = "监控管理"
    description = "监控管理模块"

    is_menu = True
    lock = True


class SystemMonitorControl(BaseBlueControl):

    title = "系统监控"
    description = "系统监控模块"

    is_menu = True
    lock = True


class VmMonitorControl(BaseBlueControl):

    title = "虚拟机监控"
    description = "虚拟机监控模块"

    is_menu = True
    lock = True


class LogMonitorControl(BaseBlueControl):

    title = "日志管理"
    description = "日志管理模块"

    is_menu = True
    lock = True


class AdminUserManageControl(BaseBlueControl):

    title = "admin用户管理"
    description = "admin用户管理模块"

    is_menu = True
    lock = True


class PermissionBlueprintControl(BaseBlueControl):

    title = "权限模块"
    description = "权限相关接口"

    lock = True


class PermissionTreeControl(BaseRuleControl):

    title = "权限资源树"
    description = "获取全站路由树组织结构"
    limit_roles = {PresetRoleChoices.admin}

    lock = True


class MenuControl(BaseRuleControl):

    title = "用户角色菜单"
    description = "获取用户所属角色组的动态菜单"

    lock = True


class MemberBulkImportUserControl(BaseRuleControl):

    title = "用户批量上传接口"
    description = "教师端用户批量上传"

    lock = True


class MemberListRuleControl(BaseRuleControl):

    title = "用户列表"
    description = "获取用户列表"


class MemberManagerRuleControl(BaseRuleControl):

    title = "用户管理"
    description = "用户管理"


class MemberPasswordRuleControl(BaseRuleControl):

    title = "用户密码"
    description = "更改用户密码"


class RoleSetControl(BaseRuleControl):

    title = "获取全部角色信息"
    description = "获取全部角色信息列表"
    limit_roles = {PresetRoleChoices.admin}

    lock = True


class RolePermissionControl(BaseRuleControl):

    title = "角色权限模块"
    lock = True

    class GET:
        title = "获取角色权限"
        description = "获取某个角色允许访问的路由权限"
        limit_roles = {PresetRoleChoices.admin}

    class POST:
        title = "授权角色权限"
        description = "赋予某个用户某角色权限"
        limit_roles = {PresetRoleChoices.admin}

    class PUT:
        title = "修改角色权限"
        description = "修改某个用户角色权限"
        limit_roles = {PresetRoleChoices.admin}


class RestoreFactorySettingsControl(BaseBlueControl):

    title = "系统设置"
    description = "系统设置模块"

    is_menu = True
    lock = True
    menu_name = title

    limit_roles = {PresetRoleChoices.admin}


class SystemRestoreControl(BaseBlueControl):

    title = "系统还原"
    description = "系统还原模块"

    is_menu = True
    lock = True
    menu_name = title
    menu_url = "/systemRestore"


class RestoreFactorySettingsViewControl(BaseRuleControl):

    title = "恢复出厂设置"
    description = "将靶场重置到出厂状态"

    limit_roles = {PresetRoleChoices.admin}
    lock = True


class HomeIndexControl(BaseBlueControl):

    title = "首页"
    description = "首页模块"

    limit_roles = {PresetRoleChoices.teacher, PresetRoleChoices.admin}

    is_menu = True
    menu_name = title
    menu_url = "/protal"


class HomeIndexRuleControl(BaseRuleControl):

    title = "首页接口"
    description = "首页接口"

    class POST:
        title = "查询"
        description = "查询首页数据"


class HomeRangeInfoRuleControl(BaseRuleControl):

    title = "首页场景仿真"
    description = "首页场景仿真"


class UserManagementControl(BaseBlueControl):

    title = "用户管理"
    description = "用户管理模块"

    limit_roles = {PresetRoleChoices.teacher, PresetRoleChoices.admin}

    is_menu = True
    menu_name = title


class AccountManagementControl(BaseBlueControl):

    title = "账号管理"
    description = "账号管理模块"

    is_menu = True
    menu_name = title
    menu_url = "/accountManagement"


class RangeSceneSimulationControl(BaseBlueControl):

    title = "场景仿真"
    description = "场景仿真模块"

    is_menu = True
    menu_name = title

    limit_roles = {
        PresetRoleChoices.admin,
        PresetRoleChoices.teacher,
        PresetRoleChoices.rb_pilot,
    }


class RangeSceneListControl(BaseBlueControl):

    title = "场景列表"
    description = "场景列表模块"

    is_menu = True
    menu_name = title

    menu_url = "/rangeList"


class RangeListRuleControl(BaseRuleControl):

    title = "靶场列表"
    description = "获取靶场列表分页"


class RangeInfoRuleControl(BaseRuleControl):

    title = "靶场详细信息"
    description = "获取靶场详细信息"


class RangeManageRuleControl(BaseRuleControl):

    title = "靶场操作"
    description = "获取、修改靶场信息或创建自定义靶场"

    class GET:
        title = "获取靶场信息"
        description = "获取靶场数据信息"

    class POST:
        title = "创建自定义靶场"
        description = "创建一个自定义的靶场"

    class PUT:
        title = "修改靶场信息"
        description = "修改当前靶场信息"


class RangeConfirmRuleControl(BaseRuleControl):

    title = "靶场确认保存"
    description = "靶场确认保存接口"


class RangeTopologyRuleControl(BaseRuleControl):

    title = "靶场拓扑保存"
    description = "靶场拓扑保存接口"


class RangeStartRuleControl(BaseRuleControl):

    title = "靶场开启"
    description = "靶场开启接口"


class RangeCollectRuleControl(BaseRuleControl):

    title = "靶场复制"
    description = "靶场复制接口"


class RangeVmManageRuleControl(BaseRuleControl):

    title = "靶场虚机"
    description = "靶场虚机"

    class GET:
        title = "获取虚拟机信息"
        description = "获取靶场数据信息"

    class POST:
        title = "创建虚机"
        description = "创建虚机"

    class PUT:
        title = "修改虚机"
        description = "修改虚机"


class RangeVmOperateRuleControl(BaseRuleControl):

    title = "靶场虚机操作(开关机/删除)"
    description = "靶场虚机操作"

    class POST:
        title = "开关虚机/删除虚机"
        description = "开关虚机/删除虚机"

class AllRangeVmOperateRuleControl(BaseRuleControl):

    title = "一键开启靶场所有虚机操作"
    description = "靶场虚机操作"

    class POST:
        title = "打开虚机"
        description = "打开虚机"

class RangeVmSnapshotRuleControl(BaseRuleControl):

    title = "靶场虚机快照"
    description = "靶场虚机快照"

    class GET:
        title = "查询快照"
        description = "查询快照"

    class POST:
        title = "创建快照"
        description = "创建快照"


class RangeVmInfoRuleControl(BaseRuleControl):

    title = "靶场虚机详情"
    description = "靶场虚机详情"

    class POST:
        title = "查询详情"
        description = "查询详情"


class RangeVmEnterRuleControl(BaseRuleControl):

    title = "进入虚拟机"
    description = "进入虚拟机接口"

    class POST:
        title = "进入"
        description = "进入虚拟机"


class RangeVmImageListRuleControl(BaseRuleControl):

    title = "镜像系统列表"
    description = "获取镜像系统列表"

    class GET:
        title = "查询"
        description = "镜像系统列表"


class RangeSceneTemplateLibraryControl(BaseBlueControl):

    title = "场景模板库"
    description = "场景模板库模块"

    is_menu = True
    menu_name = title

    black_roles = {PresetRoleChoices.rb_pilot}

    menu_url = "/templateLibrary"


class DeleteVmEnvControl(BaseRuleControl):

    title = "删除已克隆靶场"
    description = "删除靶场列表中靶场"

    lock = True

    black_roles = {PresetRoleChoices.rb_pilot}


class SecurityGroupRuleControl(BaseRuleControl):

    title = "安全组管理"
    description = "安全组管理"


class SecurityGroupListRuleControl(BaseRuleControl):

    title = "安全组列表"
    description = "安全组列表"


class SecurityGroupAssociatedRuleControl(BaseRuleControl):

    title = "虚机安全组管理"
    description = "虚机安全组管理"

    class GET:
        title = "查询"
        description = "虚机安全组查询"

    class POST:
        title = "关联安全组"
        description = "虚机关联安全组"


class SecurityGroupRuleRuleControl(BaseRuleControl):

    title = "安全组规则管理"
    description = "安全组规则管理"

    class GET:
        title = "查询安全组规则"
        description = "查询安全组规则"

    class POST:
        title = "创建安全组规则"
        description = "创建安全组规则"

    class DELETE:
        title = "删除安全组规则"
        description = "删除安全组规则"


class VmRangeInfosRuleControl(BaseRuleControl):

    title = "比赛关联/克隆靶场后，查看拓扑"
    description = "比赛关联/克隆靶场后，查看拓扑"

    class GET:
        title = "查询靶场拓扑"
        description = "查询靶场拓扑"

    class POST:
        title = "查看"
        description = "比赛关联/克隆靶场后，查看拓扑"


class ActiveDeleteVmRuleControl(BaseRuleControl):

    title = "删除指定靶场下的虚拟机"
    description = "删除指定靶场下的虚拟机"


class TaasRuleControl(BaseRuleControl):

    title = "镜像端口设置"
    description = "镜像端口设置"


class TaasFlowRuleControl(BaseRuleControl):

    title = "审计管理"
    description = "审计管理"


class SwitchNetworkRuleControl(BaseRuleControl):

    title = "交换机管理"
    description = "交换机管理"


class ConnectDeviceRuleControl(BaseRuleControl):

    title = "交换机连接线"
    description = "连接/取消连接交换机"

    class POST:
        title = "创建连线"
        description = "创建连线"

    class DELETE:
        title = "删除连线"
        description = "删除连线"


class SubnetPortRuleControl(BaseRuleControl):

    title = "给交换机创建port"
    description = "给交换机创建port"


class VmPortBindingRuleControl(BaseRuleControl):

    title = "查询虚拟机在开机时可选的端口"
    description = "查询虚拟机在开机时可选的端口"


class RouterRuleControl(BaseRuleControl):

    title = "路由管理"
    description = "路由查询/创建/删除"


class SwitchCidrRuleControl(BaseRuleControl):

    title = "查看靶场可用cidr"
    description = "查询当前靶场可用cidr"


class RouterTablesRuleControl(BaseRuleControl):

    title = "静态路由表管理"
    description = "静态路由表管理"


class ContestInfoRuleControl(BaseRuleControl):

    title = "获取靶场内置赛题信息"
    description = "获取靶场内置赛题信息接口"


class BindIssueRuleControl(BaseRuleControl):

    title = "虚拟机绑定赛题"
    description = "虚拟机绑定赛题接口"


class BindIssueListRuleControl(BaseRuleControl):

    title = "查看虚拟机已绑定的赛题"
    description = "查看虚拟机已绑定的赛题接口"


class CtfQuestionManagementControl(BaseBlueControl):

    # title = "题库管理"
    title = "实训平台"
    # description = "题库管理模块"
    description = "实训平台模块"
    is_menu = True
    menu_name = title

    limit_roles = {PresetRoleChoices.teacher, PresetRoleChoices.admin}


class CtfSystemQuestionBankListControl(BaseBlueControl):

    title = "系统题库"
    description = "场景系统模块"

    is_menu = True
    menu_name = title

    menu_url = "/ctfQuestionBankList"


class CtfMyQuestionBankListControl(BaseBlueControl):

    title = "我的题库"
    description = "我的题库模块"

    is_menu = True
    menu_name = title

    menu_url = "/myctfQuestionBankList"


class SafetyKnowledgeControl(BaseBlueControl):

    title = "安全知识"
    description = "安全知识模块"

    is_menu = True
    menu_name = title

    limit_roles = {PresetRoleChoices.teacher, PresetRoleChoices.admin}


class SystemCoursesControl(BaseBlueControl):

    title = "系统课题"
    description = "系统课题模块"

    is_menu = True
    menu_name = title

    menu_url = "/systemCourses"


class KnowledgeCoursesControl(BaseBlueControl):

    title = "知识课题"
    description = "知识课题模块"

    is_menu = True
    menu_name = title

    menu_url = "/myCourses"


class SystemCoursewareControl(BaseBlueControl):

    title = "系统课件"
    description = "系统课件模块"

    is_menu = True
    menu_name = title

    menu_url = "/systemCourseware"


class MyCoursewareControl(BaseBlueControl):

    title = "我的课件"
    description = "我的课件模块"

    is_menu = True
    menu_name = title

    menu_url = "/coursewareList"


class CtfCompetitionDrillControl(BaseBlueControl):

    is_menu = True
    menu_name = "竞技演练"

    title = "竞技演练"
    description = "比赛模块相关"

    black_roles = {PresetRoleChoices.student}


class AthleticsCompetitionControl(BaseBlueControl):

    title = "竞技比赛"
    description = "竞技比赛模块"

    is_menu = True
    menu_name = title
    menu_url = "/ctfMatchList"

    limit_roles = {PresetRoleChoices.teacher, PresetRoleChoices.admin}

    black_roles = {PresetRoleChoices.audience}


class CombatMatchCompetitionControl(BaseBlueControl):

    title = "红蓝对抗"
    description = "红蓝对抗模块"

    is_menu = True
    menu_name = title
    menu_url = {
        PresetRoleChoices.admin: "/combatMatchList",
        PresetRoleChoices.teacher: "/combatMatchList",
        PresetRoleChoices.rb_pilot: "/combatMatchList",
        PresetRoleChoices.rb_referee: "/refereeList",
        PresetRoleChoices.audience: "/audienceList",
    }


class CTFRedBlueManageControl(BaseRuleControl):

    title = "红蓝对抗比赛操作"
    description = "获取、修改靶场信息或创建自定义红蓝对抗赛"

    class POST:
        title = "创建红蓝对抗赛"
        description = "创建自定义红蓝对抗赛"

        black_roles = {PresetRoleChoices.rb_pilot}


class CTFRedBlueManageListRuleControl(BaseRuleControl):

    title = "红蓝比赛列表"
    description = "红蓝比赛列表"


class CTFNoticeInfo(BaseRuleControl):

    title = "ctf公告信息"
    description = "ctf公告信息"

    class GET:
        title = "获取公告信息"
        description = "获取公告信息"

    class POST:
        title = "创建公告"
        description = "创建公告"

    class DELETE:
        title = "删除公告"
        description = "删除公告"



class CTFRedBlueCloseRuleControl(BaseRuleControl):

    title = "关闭红蓝对抗赛"
    description = "关闭红蓝对抗赛"

    class POST:
        title = "关闭比赛"
        description = "关闭红蓝对抗赛"


class CTFRedBlueScoreRuleControl(BaseRuleControl):

    title = "红蓝攻防成绩"
    description = "红蓝攻防成绩接口"

class CTFRedBlueScoreInfoRuleControl(BaseRuleControl):
    title = "红蓝攻防成绩"
    description = "红蓝攻防成绩接口"

class CTFRedBlueScreenRuleControl(BaseRuleControl):

    title = "红蓝比赛大屏"
    description = "红蓝比赛大屏接口"

class CTFRedBlueQuestionCountControl(BaseRuleControl):
    title = "ctf红蓝对抗已答复赛题统计"
    description = "ctf红蓝对抗已答复赛题统计"

    class GET:
        title = "ctf红蓝对抗已答复赛题统计"
        description = "ctf红蓝对抗已答复赛题统计"

class CTFRedBlueScoreCompareControl(BaseRuleControl):
    title = "每隔一小时红蓝分数对比"
    description = "每隔一小时红蓝分数对比"

    class GET:
        title = "每隔一小时红蓝分数对比"
        description = "每隔一小时红蓝分数对比"

class CTFManualJudgmentRuleControl(BaseRuleControl):

    title = "红蓝比赛人工裁决"
    description = "红蓝比赛人工裁决接口"

    class GET:
        title = "裁决详情"
        description = "裁决详情"

    class POST:
        title = "申请裁决"
        description = "申请裁决"


class RedBlueRangeScoreInfoRuleControl(BaseRuleControl):

    title = "红蓝比赛靶场得分规则"
    description = "红蓝比赛靶场得分规则"


class CtfQuestionManageRuleControl(BaseRuleControl):

    title = "ctf题库管理"
    description = "ctf题库管理接口"


class CtfQuestionListRuleControl(BaseRuleControl):

    title = "ctf题库列表"
    description = "ctf题库列表接口"


class CtfMyQuestionListRuleControl(BaseRuleControl):

    title = "我的赛题列表"
    description = "我的赛题列表接口"


class ClassManageRuleControl(BaseRuleControl):

    title = "班级管理"
    description = "班级管理接口"


class ClassListRuleControl(BaseRuleControl):

    title = "班级列表"
    description = "班级列表接口"


class ClassUserRuleControl(BaseRuleControl):

    title = "班级学生管理"
    description = "班级学生管理接口"


class CourseWareListRuleControl(BaseRuleControl):

    title = "课件列表"
    description = "课件列表接口"


class CourseWareManageRuleControl(BaseRuleControl):

    title = "课件管理"
    description = "课件管理接口"


class CoursewareCollectRuleControl(BaseRuleControl):

    title = "课件收藏管理"
    description = "课件收藏管理接口"


class CoursewareStatusRuleControl(BaseRuleControl):

    title = "开启/关闭课件"
    description = "开启/关闭课件接口"

    class POST:
        title = "开启/关闭"
        description = "开启/关闭课件"


class CourseManageRuleControl(BaseRuleControl):
    title = "课程管理"
    description = "课程管理接口"


class CourseListRuleControl(BaseRuleControl):
    title = "课程列表"
    description = "课程列表接口"


class CourseJoinRuleControl(BaseRuleControl):
    title = "课程用户管理"
    description = "课程用户管理接口"

    class POST:
        title = "更新课程用户"
        description = "更新课程用户"


class CourseStatusRuleControl(BaseRuleControl):
    title = "课程状态管理"
    description = "课程状态管理接口"

    class POST:
        title = "开启/关闭课程"
        description = "开启/关闭课程"


class CTFmathRuleControl(BaseRuleControl):
    title = "ctf比赛管理"
    description = "ctf比赛管理接口"


class CTFTempRangeLockRuleControl(BaseRuleControl):
    title = "锁定ctf比赛与靶场"
    description = "锁定ctf比赛与靶场接口"

    class POST:
        title = "锁定"
        description = "锁定ctf比赛与靶场"


class CTFmathListRuleControl(BaseRuleControl):
    title = "ctf比赛列表"
    description = "ctf比赛列表接口"


class CTFmathRangeRuleControl(BaseRuleControl):
    title = "ctf比赛关联靶场"
    description = "ctf比赛关联靶场接口"


class CTFmathStatusRuleControl(BaseRuleControl):
    title = "ctf比赛状态管理"
    description = "ctf比赛状态管理接口"

    class POST:
        title = "开启/关闭ctf比赛"
        description = "开启/关闭ctf比赛"


class CTFmonitorRuleControl(BaseRuleControl):
    title = "ctf比赛大屏"
    description = "ctf比赛大屏接口"


class CTFmathQuestionRuleControl(BaseRuleControl):
    title = "ctf比赛关卡及课题"
    description = "ctf比赛关卡及课题接口"


class CTFmathUserRuleControl(BaseRuleControl):
    title = "ctf比赛用户列表"
    description = "ctf比赛用户列表接口"


class CTFmathScoreRuleControl(BaseRuleControl):
    title = "ctf比赛用户答题分数"
    description = "ctf比赛用户答题分数接口"


class CTFmathListScoreRuleControl(BaseRuleControl):
    title = "ctf比赛分数"
    description = "ctf比赛分数接口"

class OneStudentCTFmathListScoreRuleControl(BaseRuleControl):
    itle = "ctf比赛个人分数"
    description = "ctf比赛个人分数"

class LoadBlueprintControl(BaseBlueControl):

    title = "管理端文件上传下载"
    description = "管理端文件上传下载模块"

    limit_roles = {PresetRoleChoices.teacher, PresetRoleChoices.admin}

    lock = True


class UploadFileRuleControl(BaseRuleControl):

    title = "文件上传"
    description = "文件上传"

    class POST:
        title = "上传"
        description = "上传文件"


class DeleteFileRuleControl(BaseRuleControl):
    title = "删除上传文件"
    description = "删除上传文件"

    class POST:
        title = "删除"
        description = "删除文件"


class DownloadFileRuleControl(BaseRuleControl):
    title = "文件下载"
    description = "文件下载"

    class POST:
        title = "下载"
        description = "下载文件"


class NewUploadFileRuleControl(BaseRuleControl):
    title = "文件上传(新)"
    description = "文件上传(新)"

    class POST:
        title = "上传"
        description = "上传文件"


class NewDownloadFileRuleControl(BaseRuleControl):
    title = "文件下载(新)"
    description = "文件下载(新)"

    class GET:
        title = "下载"
        description = "下载文件"


class ParLoadBlueprintControl(BaseBlueControl):

    title = "学生端文件上传下载"
    description = "学生端文件上传下载模块"

    limit_roles = {PresetRoleChoices.student}

    lock = True


class MyCourseListRuleControl(BaseRuleControl):
    title = "课程列表"
    description = "课程列表接口"


class MyCourseManageRuleControl(BaseRuleControl):
    title = "课程详情"
    description = "课程详情接口"


class VmOperateRuleControl(BaseRuleControl):
    title = "虚拟机操作"
    description = "虚拟机操作接口"

    class POST:
        title = "开关虚拟机"
        description = "开关虚拟机"


class VmEnterRuleControl(BaseRuleControl):
    title = "进入虚拟机"
    description = "进入虚拟机接口"

    class POST:
        title = "进入"
        description = "进入虚拟机"


class VmImagesUpdateDestroyAPIRuleControl(BaseRuleControl):
    title = "镜像管理"
    description = "镜像管理接口"

    class POST:
        title = "创建镜像"
        description = "创建镜像"


class FlavorsListAPIRuleControl(BaseRuleControl):
    title = "获取虚拟机配置列表"
    description = "获取虚拟机配置列表接口"


class VmImagesAPIRuleControl(BaseRuleControl):
    title = "镜像列表/分片上传"
    description = "镜像列表/上传接口"

    class GET:
        title = "列表"
        description = "列表"

    class POST:
        title = "分片上传"
        description = "分片上传"


class SystemMonitoringAPIRuleControl(BaseRuleControl):
    title = "服务器监控"
    description = "服务器监控接口"


class VirtualMachinesMonitoringAPIRuleControl(BaseRuleControl):
    title = "虚拟机监控"
    description = "虚拟机监控接口"

    class POST:
        title = "关机"
        description = "关机"


class LogsMonitoringAPIRuleControl(BaseRuleControl):
    title = "日志监控"
    description = "日志监控"


class UsersListCreateAPIRuleControl(BaseRuleControl):
    title = "用户列表/创建用户"
    description = "用户列表/创建用户接口"


class UsersRetrieveUpdateDestroyAPIRuleControl(BaseRuleControl):
    title = "用户详情/修改及删除"
    description = "用户详情/修改及删除接口"


class UsersBulkOperationsAPIRuleControl(BaseRuleControl):
    title = "批量操作"
    description = "批量操作接口"

    class GET:
        title = "导入模板下载"
        description = "导入模板下载"

    class POST:
        title = "批量导入"
        description = "批量导入"


class ChangeOwnPasswordRuleControl(BaseRuleControl):
    title = "修改个人密码"
    description = "修改个人密码接口"

    class POST:
        title = "修改"
        description = "修改"
